#include <SoftSerial.h>

int readingSentance=0;
int pos=0;
char sentance[80];

void setup()
{
  SoftSerial.begin(9600);
  Serial.begin(115200);
}

void loop()
{
  GPSparse();
}
void GPSparse(){
  byte buff[6];
  int i;
  if(SoftSerial.available()){
    if(readingSentance==1){
      if(SoftSerial.peek()!='*')
        sentance[pos++]=SoftSerial.read();
      else{
        sentance[pos]=0;
        readingSentance=0;
        pos=0;
        Serial.print("RMC:");
        Serial.println(sentance);
      }      
    }
    else if(readingSentance==2){
      if(SoftSerial.peek()!='*')
        sentance[pos++]=SoftSerial.read();
      else{
        sentance[pos]=0;
        readingSentance=0;
        pos=0;
        Serial.print("GGA:");
        Serial.println(sentance);
      }      
    }
    else if(readingSentance==3){
      if(SoftSerial.peek()!='*')
        sentance[pos++]=SoftSerial.read();
      else{
        sentance[pos]=0;
        readingSentance=0;
        pos=0;
        Serial.print("GSA:");
        Serial.println(sentance);
      }      
    }
    else if(readingSentance==4){
      if(SoftSerial.peek()!='*')
        sentance[pos++]=SoftSerial.read();
      else{
        sentance[pos]=0;
        readingSentance=0;
        pos=0;
        Serial.print("GSV:");
        Serial.println(sentance);
      }      
    }
    else if(SoftSerial.peek()=='$'){
      if(SoftSerial.available()>6){
        for (i=0; i<6; i++)
          *(buff+i)=SoftSerial.read();
        if(memcmp(buff,"$GPRMC",sizeof(buff))==0)
          readingSentance=1;
        else if(memcmp(buff,"$GPGGA",sizeof(buff))==0)
          readingSentance=2;
        else if(memcmp(buff,"$GPGSA",sizeof(buff))==0)
          readingSentance=3;
        else if(memcmp(buff,"$GPGSV",sizeof(buff))==0)
          readingSentance=4;
      }
    }
    else
      SoftSerial.read();
  }  
}   
